%li.cast
  - actor = product_parameter.product
  - intervention = product_parameter.intervention
  - product = product_parameter.product
  - variant = product_parameter.variant
  - usage = product_parameter.relevant_usage
  - if actor
    .picture
      - if actor.picture.file?
        = image_tag(actor.picture.url(:thumb))
      - elsif pictogram = actor.category.pictogram
        .picto{class: "picto-#{pictogram.gsub('_', '-')}"}
      - else
        .picto{class: 'picto-question'}

    .details
      %h3
        = link_to(actor.name, {controller: actor.class.table_name, action: :show, id: actor.id})
        = lights('stop') if product_parameter.dead and product_parameter.product.dead_at
      %p= product_parameter.name
      %p= product_parameter.model_name.human
      - if actor.is_a?(Product) && !actor.population_counting_unitary? && variant && product_parameter.quantity_unit_name && product_parameter.quantity
        %p
          - if product_parameter.is_population?
            = :x_thing.tl(x: product_parameter.quantity.round(2).l(precision: 0), thing: variant.unit_name.mb_chars.downcase)
          - elsif product_parameter.product.france_maaid.present? && product_parameter.is_a?(InterventionInput)
            %p
              %span.value= product_parameter.legal_pesticide_informations&.fetch(:name, nil)
            %p
              %span.title= :quantity.tl
              %span.value= product_parameter.input_quantity_per_area.l(precision: 2)
            - unless usage.nil?
              %p
                = succeed " : " do
                  %span.title= t(:usage)
                %span.value= usage.ephy_usage_phrase
                - authorization_calculator = Interventions::Phytosanitary::InterventionInputAuthorizationCalculator.for_intervention(intervention)
                - vote, messages = authorization_calculator.authorization_state(product_parameter)
                - if vote == :allowed
                  %span.value= :allowed.tl
                - elsif vote == :forbidden
                  %span.value= :forbidden.tl
                  %span.value= messages.join(', ')

              - if frequency = usage.applications_frequency
                %p
                  %span.title= :next_application_possible_on.tl
                  %span.value= (resource.stopped_at + frequency).to_date.l

              - if usage.usage_conditions
                %p
                  %span.title.smr= :usage_conditions.tl
                  %span.value= picto_tag('info-circle', color: '#3f70ce', pointer: true, data: { toggle: 'modal', target: "#usage-conditions-modal-#{product_parameter.id}" })
                = render 'usage_conditions_modal', id: product_parameter.id, usage: usage

            -# TODO: reactivate when we have updated lexicon's data
            -# if product_parameter.legal_pesticide_informations[:dose]
              %p
                %span.title= :legal_dose.tl
                %span.value= product_parameter.legal_pesticide_informations[:dose].l(precision: 2)
                = lights('stop') if product_parameter.legal_treatment_ratio > 1.0
                = lights('caution') if product_parameter.legal_treatment_ratio == 1.0
                = lights('go') if product_parameter.legal_treatment_ratio < 1.0
            -# if product_parameter.pfi_reference_dose
              %p
                %span.title= :pfi_dose.tl
                %span.value= product_parameter.pfi_reference_dose.dose.l(precision: 2)
                = lights('stop') if product_parameter.pfi_treatment_ratio > 1.0
                = lights('caution') if product_parameter.pfi_treatment_ratio == 1.0
                = lights('go') if product_parameter.pfi_treatment_ratio < 1.0
              %p
                %span.title= :pfi_treatment_ratio.tl
                %span.value= product_parameter.pfi_treatment_ratio.round(2)
          - else
            = product_parameter.quantity.l(precision: 0)
  - elsif variant
    .picture
      - if variant.picture.file?
        = image_tag(variant.picture.url(:thumb))
      - elsif pictogram = variant.category.pictogram
        .picto{class: "picto-#{pictogram.gsub('_', '-')}"}
      - else
        .picto{class: 'picto-question'}

    .details
      %h3= link_to(variant.name, {controller: variant.class.table_name, action: :show, id: variant.id})
      %p= product_parameter.name
      %p= product_parameter.model_name.human
      - if !variant.population_counting_unitary?
        %p= :x_thing.tl(x: (product_parameter.quantity_value || 0).round(2).l(precision: 0),
                        thing: variant.unit_name.mb_chars.downcase)

  - else
    .picture
      .picto{class: 'picto-question'}
    .details
      %h3= product_parameter.name
      %p= product_parameter.model_name.human


  - if intervention.participations.empty? || (product.decorate.not_worker_or_equipment? && product.decorate.no_participation?(intervention.id))
    = add_working_period_cost(product_parameter)
  - else
    - participation = product_parameter.participation if product_parameter.is_a?(InterventionDoer)
    - is_equipment = product.try(:tractor?) || product.try(:self_prepelled_equipment?)
    .periods
      - if (participation.present? && participation.has_period_with_nature?(nature: :preparation))
        - comp = product_parameter.cost_amount_computation(nature: :preparation)
        - unless comp.failed? || comp.none? || comp.quantity.zero?
          .period
            .period-type
              = image_tag('intervention_participations/action-preparation.svg', class: "period-icon")
              %h3{ class: "period-label" }= t('enumerize.intervention_working_period.nature.preparation')
            = add_working_period_cost(product_parameter, nature: :preparation)

      - if participation.present? && participation.has_period_with_nature?(nature: :travel) || product.try(:tractor?)
        - comp = product_parameter.cost_amount_computation(nature: :travel)
        - unless comp.failed? || comp.none? || comp.quantity.zero?
          .period
            .period-type
              = image_tag('intervention_participations/action-travel.svg', class: "period-icon")
              %h3{ class: "period-label" }= t('enumerize.intervention_working_period.nature.travel')
            = add_working_period_cost(product_parameter, nature: :travel)

      - if (participation.present? && participation.has_period_with_nature?(nature: :intervention)) || product.is_a?(Equipment)
        - comp = product_parameter.cost_amount_computation(nature: :intervention)
        - unless comp.failed? || comp.none? || comp.quantity.zero?
          .period
            .period-type
              = image_tag('intervention_participations/action-intervention.svg', class: "period-icon")
              %h3{ class: "period-label" }= t('enumerize.intervention_working_period.nature.intervention')
            = add_working_period_cost(product_parameter, nature: :intervention)

      - if participation.present? || is_equipment || product.is_a?(Equipment)
        .total
          %h3{ class: "total-label" }= t('labels.total')

          - if product.is_a?(Worker)
            = add_total_working_period(product_parameter)
          - elsif product.try(:tractor?)
            = add_total_working_period(product_parameter, natures: %i[travel intervention])
          - else
            = add_total_working_period(product_parameter, natures: %i[intervention])
